package net.wofly.right.validator;


import java.util.List;

import org.apache.commons.lang3.StringUtils;

import net.wofly.right.domain.RightConfig;

/**
 * 角色验证类
 * @author siqingwei
 */
public class RoleValidator {

    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");

    public static String validateSaveParams(String roleName, Integer warehouseFlag, Integer warehouseType) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isBlank(roleName)) {
            stringBuffer.append("角色名称不能为空").append(lineSeparator);
        }
        if (null == warehouseFlag) {
            stringBuffer.append("是否有库存不能为空").append(lineSeparator);
        }
        if (null == warehouseType) {
            stringBuffer.append("库存类型不能为空").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateGetUserByRoleIDParams(String roleID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isBlank(roleID)) {
            stringBuffer.append("角色ID不能为空").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateAddRightConfigParams(String roleID, String funcListID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isBlank(roleID)) {
            stringBuffer.append("角色ID不能为空").append(lineSeparator);
        }
        if (StringUtils.isBlank(funcListID)) {
            stringBuffer.append("功能ID不能为空").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static String validateAddRightConfigListParams(List<RightConfig> rightConfigs) {
        StringBuffer stringBuffer = new StringBuffer();
        if (null==rightConfigs) {
            stringBuffer.append("角色功能列表不能为空").append(lineSeparator);
        }
        
        for(RightConfig rightConfig :rightConfigs) {
        		if (StringUtils.isBlank(rightConfig.getRoleID())) {
                stringBuffer.append("角色ID不能为空").append(lineSeparator);
            }
            if (StringUtils.isBlank(rightConfig.getFuncListID())) {
                stringBuffer.append("功能ID不能为空").append(lineSeparator);
            }
        }
        
        return stringBuffer.toString();
    }
    

    public static String validateRemoveRightConfigParams(String roleID, String funcListID) {
        return validateAddRightConfigParams(roleID, funcListID);
    }
    
    public static String validateRemoveRightConfigListParams(List<String> rightConfigIDs) {
    		StringBuffer stringBuffer = new StringBuffer();
    		
    		if (null==rightConfigIDs) {
            stringBuffer.append("角色功能ID列表不能为空").append(lineSeparator);
        }
    		
    		for(String rightConfigID:rightConfigIDs) {
    			if(StringUtils.isEmpty(rightConfigID)) {
    				stringBuffer.append("角色功能ID不能为空").append(lineSeparator);
    			}
    		}
    		
        return stringBuffer.toString();
    }
    
    
}
